"use strict";

(function() {

//This must match the version in install.rdf
const currentVersion = '0.2';

const Cc = Components.classes; 
const Ci = Components.interfaces;
const prefs = Cc['@mozilla.org/preferences-service;1']
              .getService(Ci.nsIPrefService)
              .getBranch('extensions.bats@hwiechers.blogspot.com.');

const PREF_STRING = Ci.nsIPrefBranch.PREF_STRING;
const currentVersionKey = 'currentVersion';
const lastVersion = prefs.getPrefType(currentVersionKey) === PREF_STRING ?
                    prefs.getCharPref(currentVersionKey) : null;

if (currentVersion !== lastVersion) {
    addEventListener('load', function() {
        gBrowser.selectedTab = gBrowser.addTab('chrome://bats/content/update-notes.html');
    });
    prefs.setCharPref(currentVersionKey, currentVersion);
}

})();

const bats = {
    selectTab : function(tabNumber, isPinned) {
        let count = tabNumber;
        gBrowser.visibleTabs.forEach(function(element) {
            if(element.pinned === isPinned) {
                count--;
                if (count == 0)
                {
                    gBrowser.selectedTab = element;
                    return;
                }
            }
        });
    },
    selectUnpinnedTab : function(tabNumber) { bats.selectTab(tabNumber, false); },
    selectPinnedTab : function(tabNumber) { bats.selectTab(tabNumber, true); }
}
